/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bll;

import dao.TaiKhoan;
import dao.testconnection;
import dto.dlogin;
import gui.login;
import gui.loginusername;
import gui.main;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 *
 * @author HONGPHUOC
 */
public class blogin {

    public boolean  test(dlogin tk) {
        testconnection testcon = new testconnection();
        if (testcon.testconnection(tk)) {
            JOptionPane.showMessageDialog(null, "DANG NHAP THANH CONG");
            loginusername f=new loginusername();
            f.setVisible(true);
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "dang nhap khong thanh cong");
            login f=new login();
            f.setVisible(true);
            return false;
        }
    }

    public void setdlogin(dlogin tk) {
        TaiKhoan setTk = new TaiKhoan();
       // JOptionPane.showMessageDialog(null, "a");
        setTk.setTaiKhoan(tk);
    }

    public dlogin GetTaiKhoan() {
        dlogin dl = new dlogin();
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            Document doc = builder.newDocument();
            doc = builder.parse("taiKhoan.xml");
            NodeList taiKhoanList = doc.getElementsByTagName("taikhoan");
            Node taiKhoans = taiKhoanList.item(0);
            NodeList chilNodes = taiKhoans.getChildNodes();
            Node hostNode = chilNodes.item(0);
            Node portNode = chilNodes.item(1);
            Node userNameNode = chilNodes.item(2);
            Node passNode = chilNodes.item(3);
            Node dataNode = chilNodes.item(4);
            //JOptionPane.showMessageDialog(null, hostNode.getTextContent());
            dl = new dlogin(hostNode.getTextContent(), portNode.getTextContent(), userNameNode.getTextContent(), passNode.getTextContent(), dataNode.getTextContent());;
          
        } catch (SAXException ex) {
            Logger.getLogger(blogin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(blogin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(blogin.class.getName()).log(Level.SEVERE, null, ex);
        }
      return dl;
    }
}
